package hn.cch.engine;

import hn.cch.cache.DefaultCache;
import hn.cch.common.core.Bean;
import hn.cch.common.core.Log;
import hn.cch.common.core.Param;
import hn.cch.common.core.Path;
import hn.cch.netty.http.HttpServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class EngineBoot {

    private static Logger logger = LoggerFactory.getLogger(EngineBoot.class);


    public static void main(String[] args) {

        //加载日志
        Log.newLog(Path.LOG_PATH);
        //加载实例
        Bean.newBean(Path.BEAN_PATH);

        //初始化配置文件
        Param.initParam(new File(Path.PARAM_PATH));


        //启动缓存
        cache();
        //启动服务
        netty();

    }

    public static void cache() {


        logger.info("cache start");

        //读取文件配置缓存
        DefaultCache.initCache(Path.CACHE_PATH);
        //添加默认缓存
        DefaultCache.addDefault();

        logger.info("cache success");

    }

    public static void netty() {


        logger.info("netty start");
        Integer listenPort = Param.getInteger(Param.listen_port);
        HttpServer httpServer = new HttpServer(listenPort);
        Thread thread = new Thread(httpServer);
        thread.start();
        logger.info("netty success");
    }

}
